import java.math.BigDecimal;

/**
 * CreditCard is an account that has a "limit"
 * and it's own special withdrawal.
 * 
 * The limit is a negative number, indicating debt.
 * A balance of -100 would mean the Customer owes
 * $100. For this reason it can't use withdrawal
 * inherited from Account.
 * 
 * @author svene
 *
 */
public class CreditCard extends Account
{
	public BigDecimal limit; // you cannot spend more than this limit
		
	public CreditCard(Customer ccCustomer, BigDecimal limit)
	{
		super(ccCustomer);
		this.limit = limit;
	}
	
	public boolean withdraw(BigDecimal amount){
		return this.useCredit(amount);
	}
	
	/**
	 * Amount is always a negative number, so we use add.
	 * If the current balance, plus the amount (negative number)
	 * is greater than the limit (i.e. -800 > -1000) then the
	 * transaction happens.
	 * 
	 * @param amount
	 * @return
	 */
	public boolean useCredit(BigDecimal amount)
	{
		if(balance.add(amount).compareTo(limit)== 1)
		{
			balance.add(amount);
			return true;
		}
		else
		{
			return false;
		}
	}
}
